package com.shaoshaohuo.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.Specification;

import java.util.List;

public class SpecificationsGridviewAdapter<T> extends MyBaseAdapter<Specification> {

    private List<Integer> selectPositions;

    public SpecificationsGridviewAdapter(Context ctx, List<Specification> list,List<Integer> selectPositions, boolean flag) {
        super(ctx, list, flag);
        this.selectPositions = selectPositions;
    }

    @Override
    public Specification getItem(int arg0) {
        return list.get(arg0);
    }

    @Override
    public View getView(int pos, View convertView, ViewGroup group) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.view_added_service_item, null);
            holder = new ViewHolder();
            holder.titleText = (TextView) convertView.findViewById(R.id.textview_text);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Specification item = list.get(pos);
        if (selectPositions.contains(pos)) {
            convertView.setActivated(true);
        } else {
            convertView.setActivated(false);
        }

        holder.titleText.setText(item.specification_val);
        return convertView;
    }

    static class ViewHolder {
        TextView titleText;
    }

}
